home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: fast copy
- Date: 14 Feb 1996 22:51:19 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4ftp17$go3@news1.usa.pipeline.com>
- NNTP-Posting-Host: pipe15.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Feb 12, 1996 22:05:49 in article <fast copy>, 'cbenoit@mail.imaginet.fr
- (Christophe Benoit)' wrote:
-
-
- >Do you know the best method (run-time performance) to copy a file ?
-
- I assume you mean best in terms of time.
-
- 1. Open the file in binary mode.
- 2. Determine its size
- 3. Allocate a buffer large enough for the entire file.
- 4. Read it in in one fread.
- 5. Open output file and fwrite entire buffer in one whoosh.
- 6. Close both.
-
- You can beat this using assembler, but such gains are usually
- insignificant. If the file is too large to fit into one buffer, split
- it into as large blocks as possible to reduce the number of
- calls to IO routines.
-
- --
- Pete Grant
- Kalevi, Inc.
- Software Engineering & development
-